﻿/**	std_algorithm.hpp
 *	----	Create Time Stamp	--2009-07-08 20:30:27--
 *------------------------------------------------------------------------------
 *	Mean	:
 *	Author	:Nick Shallery	(nicknide@gmail.com)
 *	Version	:1.0.0.2	(2009-07-12 11:32:22)
 *------------------------------------------------------------------------------
**/	/*YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.*/

#if			!defined(__LOLIX__TOY__STD_ALGORITHM__NICK__K_IN_G__)
#define		__LOLIX__TOY__STD_ALGORITHM__NICK__K_IN_G__

//==============================================================================
//--------------------------------------------------------------------------
#if			!defined(__LOLIX__TOY__STD_FUNCTIONAL__NICK__K_IN_G__)
	#include	"./std_functional.hpp"
#endif	//	!defined(__LOLIX__TOY__STD_FUNCTIONAL__NICK__K_IN_G__)

namespace lolix{
#if			!defined(__LOLIX_PROC_DEFINE__SWAP__)
#define		__LOLIX_PROC_DEFINE__SWAP__
	template<typename _Tl, typename _Tr>
	LOLIX_INLINE_CALL void swap(_Tl& tl, _Tr& tr)
		{
		_Tl tmp(tl);
		tl = tr;
		tr = tmp;
		}
#endif	//	!defined(__LOLIX_PROC_DEFINE__SWAP__)
}
namespace lolix{namespace toy{
	template<typename _TyBegin, typename _TyEnd, typename _TyValue, typename _TyCmp>
	_TyBegin lower_bound(_TyBegin bg, _TyEnd ed, _TyValue& val, _TyCmp& cmp)
		{
		while ( bg != ed )
			{
			_TyBegin iter = bg + (ed - bg)/2;
			if ( cmp(*iter, val) )
				++(bg = iter);
			else
				ed = iter;
			}

		return bg;
		}

	template<typename _TyBegin, typename _TyEnd, typename _TyValue>
	_TyBegin lower_bound(_TyBegin bg, _TyEnd ed, _TyValue& val)
		{
		return lower_bound(bg, ed, val, less<_TyValue>());
		}

	template<typename _TyBegin, typename _TyEnd, typename _TyValue, typename _TyCmp>
	_TyBegin upper_bound(_TyBegin bg, _TyEnd ed, _TyValue& val, _TyCmp& cmp)
		{
		while ( bg != ed )
			{
			_TyBegin iter = bg + (ed - bg)/2;
			if ( cmp(val, *iter) )
				ed = iter;
			else
				++(bg = iter);
			}

		return bg;
		}

	template<typename _TyBegin, typename _TyEnd, typename _TyValue>
	_TyBegin upper_bound(_TyBegin bg, _TyEnd ed, _TyValue& val)
		{
		return upper_bound(bg, ed, val, less<_TyValue>());
		}
}}


//--------------------------------------------------------------------------
//==============================================================================
#endif	//	!defined(__LOLIX__TOY__STD_ALGORITHM__NICK__K_IN_G__)
